/*!
//      
//      \file	k2k_StateMachineTypes.h
//      
//      \author	Copyright 2010 Valentina Vuksic <vuksv1@bfh.ch>, Beat Liechti <liecb2@bfh.ch>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//
//		Declares the types for states, events, and state handlers
//      
//      \brief		CAS-EBX-03 Projektarbeit 
//      			Valentina Vuksic (VUKSV1), Beat Liechti (LIECB2)
//      			State, event, and state handler types for the k2k (Kaffee2000) application
//      \version	1.0
//      \date		2010-04-11
//      \remark		Last Modifications:
//      \remark  	v1.0, VUKSV1/LIECB2, 2010-04-11 Initial release
//
*/

#ifndef __k2k_StateMachineTypes__
#define __k2k_StateMachineTypes__

#include <stdlib.h>

#include "k2k_GlobalDefines.h"

/*! Nano-X */
#include "k2k_NanoX.h"

#include "k2k_StateHandlerData.h"

#define k2k_STATEHANDLER_ERR_SUCCESS					0x00000000
#define k2k_STATEHANDLER_ERR_CREATE_SIGNAL_FAILED		0xFFFD0001
#define k2k_STATEHANDLER_ERR_CREATE_HANDLERDATA_FAILED	0xFFFD0002
#define k2k_STATEHANDLER_ERR_OPEN_DEVICES_FAILED		0xFFFD0003

/*! define signals for state handlers */
#define k2k_SIG_ESPR	(SIGRTMIN+1)
#define k2k_SIG_MLKC	(SIGRTMIN+2)
#define k2k_SIG_RSTR	(SIGRTMIN+3)
#define k2k_SIG_CLN		(SIGRTMIN+4)

/*!
// k2k_State defines the possible states of the state machine
// \brief k2k_State enum type for ADT
*/
typedef enum k2k_State_Enum 
{ 
	STATE_OFF, 
	STATE_RDY1, 
	STATE_RDY2, 
	STATE_RSTR, 
	STATE_ESPR, 
	STATE_MLKC, 
	STATE_CLN,
	STATE_MAX 
} k2k_State;

/*!
// 3k2k_Events defines the possible events triggering status changes
// \brief k2k_Events enum type for ADT
*/
typedef enum k2k_Event_Enum 
{ 
	EVENT_S0 = '0', 
	EVENT_S1 = '1', 
	EVENT_S2 = '2', 
	EVENT_S3 = '3', 
	EVENT_S4 = '4', 
	EVENT_S5 = '5', 
	EVENT_S6 = '6', 
	EVENT_S7 = '7',	
	EVENT_T0 = '8',	
	EVENT_T1 = '9',	
	EVENT_T2 = ':',	
	EVENT_T3 = ';',		
	EVENT_TIMER,	
	EVENT_MAX
} k2k_Event;

/*!
// k2k_StateHandler defines the function pointer for state handlers
// \brief k2k_StateHandler function pointer type for ADT
//
// \param event describes the event that happened
// \param previousState describes the previous state
// \param customData points to custom data (typically the corresponding ADT struct)
//
// \return next state of the event machine
*/
typedef k2k_State (*k2k_StateHandlerFunc)(k2k_Event event, k2k_State previousState, k2k_StateHandlerData *handlerData);

/*!
//
// Get a text describing the event
//
// \param event is the event to describe
// 
// \return string describing the event
//
*/
char *k2k_StateMachineTypes_GetEventText(k2k_Event event);

/*!
//
// Get a text describing the state
//
// \param state is the state to describes
// 
// \return string describing the state
//
*/
char *k2k_StateMachineTypes_GetStateText(k2k_State state);

#endif
